home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
3_0
/
DOUBLEDE
/
UTILITIE.C
< prev
next >
Wrap
C/C++ Source or Header
|
1988-05-29
|
3KB
|
117 lines
#include "MacTypes.h"
#include "Quickdraw.h"
#include "WindowMgr.h"
#include "MemoryMgr.h"
/********************************************************************
centerwindow(wind,r)
WindowPtr wind;
Rect *r;
centers the window referenced by the WindowPtr: wind within
the Rect referenced by the Rect* r. To center a window in
the Macintosh screen, (or primary screen if using a Mac II),
call...
centerwindow(theWindow,&screenBits.bounds);
*******************************************************************/
centerwindow(wind,r)
WindowPtr wind;
Rect *r;
{
Rect r2;
int windW,windH;
int rectW,rectH;
r2 = wind->portRect;
windW = r2.right-r2.left;
windH = r2.bottom-r2.top;
rectW = r->right - r->left;
rectH = r->bottom - r->top;
MoveWindow (wind,
r->left+(rectW-windW)/2,
r->top+(rectH-windH)/2,
FALSE);
}
/********************************************************************
centerrect(r1,r2)
Rect *r1,*r2;
centers the rectangle referenced by the Rect* r1 within
the Rect referenced by the Rect* r2. To center the Rect
innerRect within the Rect outerRect, call...
centerrect(&innerRect,&outerRect);
*******************************************************************/
centerrect(r1,r2)
Rect *r1,*r2;
{
OffsetRect (r1,
((r2->right-r2->left)-(r1->right-r1->left))/2-r1->left,
((r2->bottom-r2->top)-(r1->bottom-r1->top))/2-r1->top);
}
/********************************************************************
Boolean TrackMyRect(aPoint,r1,rad1,rad2)
Point aPoint;
Rect *r1;
int rad1,rad2;
TrackMyRect() treats the Rect referenced by *r1 much like
the TrackControl(ControlHandle) of the Control Manager. The
point passed by aPoint should be the local coordinates of the
mouse down location in the window in which the Rect resides,
and should initially be called with the mouse location inside
of the Rect.
rad1 and rad2 are radii for rounded rects, pass 0 in these
values if the Rect is not rounded.
Sample Code Fragment....
Point thePoint;
Rect myRect;
Boolean rectSelected;
thePoint = theEvent.where;
GlobalToLocal(&thePoint);
if (PtInRect(thePoint,&myRect))
rectSelected = TrackMyRect(thePoint,&myRect,0,0);
*******************************************************************/
Boolean TrackMyRect(aPoint,r1,rad1,rad2)
Point aPoint;
Rect *r1;
int rad1,rad2;
{
Boolean returnVal = TRUE;
InvertRoundRect(r1,rad1,rad2);
do {
GetMouse(&aPoint);
if (PtInRect(aPoint,r1) != returnVal)
{
returnVal = !returnVal;
InvertRoundRect(r1,rad1,rad2);
SystemTask();
}
} while (StillDown());
GetMouse(&aPoint);
if (PtInRect(aPoint,r1)){
InvertRoundRect(r1,rad1,rad2);
return(TRUE);
}
else
return(FALSE);
}